package com.yl.mybatis.connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


/**
 * @description: 数据库连接池
 * @author: yoozhoo
 * @modified By: yoozhoo
 * @date: Created in 2021/1/4 1:57 下午
 * @version:v1.0
 */
public class DbUtil {

    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    static {
      driver="com.mysql.jdbc.Driver";
      url="jdbc:mysql://localhost:3306/mybatis";
      username="root";
      password="root";
    }

    public static Connection open()
    {
      try {
        Class.forName(driver);
        return DriverManager.getConnection(url,username, password);
      } catch (Exception e) {
        System.out.println("数据库连接失败！");
        e.printStackTrace();
      }

      return null;
    }

    public static void close(Connection conn)
    {
      if(conn!=null)
      {
        try {
          conn.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }


  }
